/**
 * @name constant.js
 * @description 常量定义
 * @author 'fwq'
 * @time 2021/10/17
 */
import { UUID2 } from "./utils";
import { isString } from "./validate";

const fontUrl = "//at.alicdn.com/t/font_2638773_4vvhmao4tz4.css";
const baseUrl = import.meta.env.VITE_APP_URL;

const draggableOption = {
  parent: true,
  scale: 1,
  draggable: true, // 定义组件是否可以拖动。
  resizable: true, // 定义组件是否可以调整大小。
  grid: [1, 1],
};
const SketchRuleOption = {
  lang: "zh-CN",
  scale: 0.8, //658813476562495, //1,
  thick: 22, // thick size 辅助尺 大小
  width: 1139,
  height: 785,
  startX: -50, // x at the beginning of the ruler
  startY: -50,
  shadow: {
    x: 0,
    y: 0,
    width: 0,
    height: 0,
  }, // 阴影标尺上的大小和起始坐标
  lines: {
    // 默认显示辅助线位置
    h: [],
    v: [],
  },
  palette: {
    bgColor: "#21212180",
    longfgColor: "#BABBBC",
    shortfgColor: "#C8CDD0",
    fontColor: "#fff",
    shadowColor: "transparent",
    lineColor: "#2196f3",
    borderColor: "#21212180",
    cornerActiveColor: "#fff",
  },
};
/**
 * 构建 绝对布局布局块对象
 * @param payload
 * @returns
 */
const AbsoluteLayoutItem = function () {
  let layoutItem = {
    id: UUID2(16),
    layoutConfigData: {
      "width": 1920,
      "widthPixelUnit": "px",
      "height": 1080,
      "heightPixelUnit": "px",
      "backgroundColor": "#0E2B43",
      "syncSetPageBgColor": true,
      "dragPixel": 1,
      "thumbnailPath": "",
      "imageRelativePath": "",
      "backgroundRepeat": "no-repeat",
      "backgroundSize": "100% 100%",
      "styleFilter_use": false,
      "styleFilter_hueRotate": 0,
      "styleFilter_contrast": 100,
      "styleFilter_opacity": 100,
      "styleFilter_saturate": 100,
      "styleFilter_brightness": 100,
      "customStyleCode": "",
      layoutItems: []
    },
  };

  return layoutItem;
};

function setDataSourceConfig(config, compId, staticData, data, type = "static") {
  config.source = {
    // id
    id: UUID2(6),
    // 组件Id
    compId,
    type,
    requestId: "",
    requestData: [],
    // 包含的字段
    fields: {},
    render: "render",
    // 自动更新
    useAutoUpdate: false,
    // 自动更新时间
    autoUpdate: 1,
    dataFilters: [],
    config: {
      useFilter: false,
      data: isString(data) ? data : JSON.stringify(data)
    },
    staticData,
  };
  return config;
}

export {
  fontUrl,
  baseUrl,
  draggableOption,
  SketchRuleOption,
  AbsoluteLayoutItem,
  setDataSourceConfig
};
